#!/usr/bin/env python
import time,MySQLdb

conn=MySQLdb.connect(host='localhost',user='root',passwd='Redhat@123',db='memory')
conn.autocommit(True)
cur=conn.cursor()

def getMem():
  f=open('/proc/meminfo','r')
  MemTotal=int(f.readline().split()[1])
  MemFree=int(f.readline().split()[1])
  Buffers=int(f.readline().split()[1])
  Cached=int(f.readline().split()[1])
  used = MemTotal-MemFree-Buffers-Cached
  t = int(time.time())
  sql = 'insert into memory (memory,time) value (%s,%s)' %(used/1024,t)
  cur.execute(sql)
  print 'ok'

while True:
  time.sleep(1)
  getMem()
  
